import { ethers } from 'ethers';
import { defineStore } from 'pinia'
import { ref } from 'vue';
import { IUserInfo } from '../../model/user';

export const userStore = defineStore('user',
  () => {
    const address = ref("");
    const sign = ref("");
    const info = ref<IUserInfo>()
    function updateAddress(newVal) {
      // address.value = '0xa3aA89B7313C0A9698FEDc1Cf240335c92c2083e' || ethers.getAddress(newVal);
      address.value = ethers.getAddress(newVal);
    }
    function updateSign(newVal) {
      sign.value = newVal;
    }
    function updateInfo(newVal: IUserInfo) {
      info.value = newVal;
    }
    return { address, sign, info, updateAddress, updateSign, updateInfo }
  }, {
  persist: {
    storage: sessionStorage,
  },
}
)